package com.lagou.homework4;

public class TicketBuyers implements Runnable {
    TicketerBunker ticketBunker;
    String userName;
    public TicketBuyers(String name,TicketerBunker tb) {
        this.ticketBunker = tb;
        this.userName = name;
    }

    @Override
    public void run() {
        System.out.println("开启线程：" + this.userName);
//        for (int i =0; i<=100 ; i++){
////            try {
////                Thread.sleep(1000);
////            } catch (InterruptedException e) {
////                e.printStackTrace();
////            }
//            int num = this.ticketBunker.getTickets(this.userName);
//        }
        while (true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            int num = this.ticketBunker.getTickets(this.userName);
            if (0 == num){
                break;
            }
        }
    }
}
